﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics.Dynamics.Contacts;

namespace RacePlatformer.Object
{
    public class Candy : GameObject
    {

        /// <summary>
        /// Object which functions as a candy item
        /// </summary>
        /// <param name="maingame">The 'MainGame.cs' class that needs to be passed</param>
        /// <param name="world">The world class that needs to be passed, is required to create objects and fixtures</param>
        /// <param name="size">the size of the object</param>
        /// <param name="position">the position of the object(in normal units)</param>
        /// <param name="bodytype">the bodytype of the object</param>
        /// <param name="mass">the mass of the object</param>
        public Candy(MainGame maingame, World world, Vector2 size, Vector2 position, BodyType bodytype, float mass,int levelID)
            : base(maingame, world, size, position, bodytype, mass,levelID)
        {
            this.body.FixedRotation = false;
            this.body.Friction = 0f;
            this.body.Restitution = 0f;
            this.body.LinearDamping = 2.0f;
            this.layer = 0.5f;
            this.body.OnCollision += OnColl;
        }
        public override void Update(GameTime gametime)
        {
            mainAnimation.update(gametime);
        }
        private bool OnColl(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            if (fixtureB.CollisionGroup == Manager.CollisionGroupManager.PLAYER)
            {
                maingame.hud.candyCount++;
                this.body.Dispose();
                maingame.goManager.gameObjects.Remove(this);
            }
            return true;
        }
        public override void LoadContent()
        {
          this.mainAnimation = new Manager.Animation(maingame, "Objects/candy_strip", 18, 160, 64, TimeSpan.FromSeconds(0.05f), Manager.Animation.AnimationType.contious);
        }
    }
}
